﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhDataAcess.produceDAL;
using dhSystemBLL.produceBLL;
using dhSystemBLL.orderData;
using dhDataAcess.produceLinq;

namespace dhsystem.produceForm
{
    public partial class FrmorderStockReturnDetailAdd : Form
    {
        orderStockReturnBLL orderStockReturn = new orderStockReturnBLL();
        orderStockReturnDetailModel orderStockReturnDetailRow = new orderStockReturnDetailModel();
        productListBLL product = new productListBLL();
        orderDetailBLL orderDetail = new orderDetailBLL();
        BindingSource BindingSourceorderStockReturnDetailAdd;
        string state;
        string billNo;
        //绑定数据源
        public FrmorderStockReturnDetailAdd(BindingSource bindingSourceorderStockReturnDetail, string _state, string _billNo)
        {
            InitializeComponent();
            BindingSourceorderStockReturnDetailAdd = bindingSourceorderStockReturnDetail;
            state = _state;
            billNo = _billNo;
        }
        //打开窗口时绑定数据
        private void FrmorderStockReturnDetailAdd_Load(object sender, EventArgs e)
        {
            bindingSourceproductList.DataSource = product.getproductListAll();
            comboBoxpName.DataSource = bindingSourceproductList;
            comboBoxpName.DisplayMember = "pname";
            comboBoxpName.ValueMember = "pname";
            bindingSourceorderDetail.DataSource = orderDetail.getorderDetailAll();
            comboBoxorderDetailNo.DataSource = bindingSourceorderDetail;
            comboBoxorderDetailNo.DisplayMember = "orderDetailNo";
            comboBoxorderDetailNo.ValueMember = "orderDetailNo";

            if (state == "编辑")
            {
                textbillNo.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "billNo");
                comboBoxpName.DataBindings.Add("selectedvalue", BindingSourceorderStockReturnDetailAdd, "pName");
                comboBoxorderDetailNo.DataBindings.Add("selectedvalue", BindingSourceorderStockReturnDetailAdd, "orderDetailNo");
                textqty.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "qty");
                textunit.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "unit");
                textboxno.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "boxno");
                textboxList.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "boxList");
                textweightJ.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "weightJ");
                textweightM.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "weightM");
                textmark.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "mark");
                //textid.DataBindings.Add("text", BindingSourcescrlDetailAdd, "recordid");
                // BindingSourceDetailAdd.AddNew();
                //textproductname.Text = productname;
            }
            if (state == "新增")
            {
                textbillNo.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "billNo");
                comboBoxpName.DataBindings.Add("selectedvalue", BindingSourceorderStockReturnDetailAdd, "pName");
                comboBoxorderDetailNo.DataBindings.Add("selectedvalue", BindingSourceorderStockReturnDetailAdd, "orderDetailNo");
                textqty.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "qty");
                textunit.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "unit");
                textboxno.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "boxno");
                textboxList.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "boxList");
                textweightJ.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "weightJ");
                textweightM.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "weightM");
                textmark.DataBindings.Add("text", BindingSourceorderStockReturnDetailAdd, "mark");
                // textid.DataBindings.Add("text", BindingSourcescrlDetailAdd, "recordid");
                BindingSourceorderStockReturnDetailAdd.AddNew();
                textbillNo.Text = billNo;
            }

            comboBoxpName.Focus();
        }
        //保存按钮，插入或修改数据
        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否保存资料！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {

                    BindingSourceorderStockReturnDetailAdd.EndEdit(); //编辑到完成，写到数据源
                    BindingSourceorderStockReturnDetailAdd.CancelEdit(); //刷新数据作用

                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        //取消按钮
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            BindingSourceorderStockReturnDetailAdd.CancelEdit();
            this.Close();
        }
    }
}
